package com.example.adapterviewfilpperdemo;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class MyFilpperAdapter extends BaseAdapter {
    private Context context;
    private int[] ids;


    public MyFilpperAdapter(Context context, int[] ids) {
        this.context = context;
        this.ids = ids;
    }

    @Override
    public int getCount() {
        return ids.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView view;
        if(null == convertView){
            view = new ImageView(context);
            view.setScaleType(ImageView.ScaleType.FIT_XY);
            view.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT
            ));
            convertView = view;
        }else {
            view = (ImageView)convertView;
        }

        view.setImageResource(ids[position]);
        return view;
    }
}
